home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / Caml Light 0.7 / examples / minilogo / crayon.ml < prev    next >
Encoding:
Text File  |  1995-07-03  |  1.1 KB  |  45 lines  |  [TEXT/MPS ]

  1. #open "graphics";;
  2.  
  3. open_graph "";;
  4.  
  5. let round x =
  6.   if x >=. 0.0
  7.   then int_of_float (x +. 0.5)
  8.   else - (int_of_float (-. x +. 0.5));;
  9.  
  10. type état =
  11.    { mutable X : float; mutable Y : float;
  12.      mutable Visée : float; mutable Levé : bool };;
  13.  
  14. let crayon = { X = 0.0; Y = 0.0; Visée = 0.0; Levé = false };;
  15.  
  16. let fixe_crayon b = crayon.Levé <- b;;
  17.  
  18. let pi_sur_180 =
  19.     let pi = 4.0 *. (atan 1.0) in pi /. 180.0;;
  20.  
  21. let tourne angle =
  22.     crayon.Visée <- (crayon.Visée +. angle *. pi_sur_180);;
  23.  
  24. let avance d =
  25.     let dx = d *. cos (crayon.Visée)
  26.     and dy = d *. sin (crayon.Visée) in
  27.     crayon.X <- crayon.X +. dx;
  28.     crayon.Y <- crayon.Y +. dy;
  29.     if crayon.Levé
  30.     then moveto (round crayon.X) (round crayon.Y)
  31.     else lineto (round crayon.X) (round crayon.Y);;
  32.  
  33. let couleur_du_tracé = foreground;;
  34. let couleur_du_fond = background;;
  35. let zéro_x = float_of_int ((size_x ()) / 2);;
  36. let zéro_y = float_of_int ((size_y ()) / 2);;
  37. let vide_écran () =
  38.     clear_graph();
  39.     set_color couleur_du_tracé;
  40.     crayon.X <- zéro_x;
  41.     crayon.Y <- zéro_y;
  42.     crayon.Visée <- 0.0;
  43.     crayon.Levé <- false;
  44.     moveto (round crayon.X) (round crayon.Y);;
  45.